package com.demo.pattern.singleton;

/**
 * @author sourire
 * @version 1.0
 * @date 2020/8/17 16:53
 */
public class SingletonTest06 {
    public static void main(String[] args) {

        SingleTon06 instance = SingleTon06.getInstance();
        SingleTon06 instance2 = SingleTon06.getInstance();
        System.out.println(instance == instance2);
        System.out.println("instance === " + instance.hashCode());
        System.out.println("instance2 === " + instance2.hashCode());
    }
}

//静态内部类

class SingleTon06 {
    //构造器私有化
    private SingleTon06() {
    }
    //静态内部类
    private static class SingleTonInstance{
        private static SingleTon06 instance = new SingleTon06();
    } ;
    //对外提供静态的调用方法
    public static  SingleTon06 getInstance() {
        return SingleTonInstance.instance;
    }
}
